//
//  HomeHeaderView.swift
//  01MicroBlog
//
//  Created by Apple on 15/8/3.
//  Copyright © 2015年 heima. All rights reserved.
//

import UIKit

let margin:CGFloat = 8
class StatusTopView: UIView {
    
    // 定义模型
    var status:Status? {
        
        didSet{

            // 设置头像
            if let url = status?.user?.imageURL! {
                iconView.sd_setImageWithURL(url)
            }
            
//             用户昵称、会员等级、会员图像
            nameLabel.text = status?.user?.name
            membershipView.image = status?.user?.memberImage
            vipView.image = status?.user?.vipImage
            
            // TODO
            timeLabel.text = "刚刚"
            destinationLabel.text = "来自火星"
        }
    }

   override init(frame: CGRect) {
        super.init(frame: frame)
    
        setUpUI()
    
    }
    
    private let width = UIScreen.mainScreen().bounds.size.width

   private func setUpUI() {
    // 添加顶部分隔视图
    let sepView = UIView()
    sepView.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
    addSubview(sepView)
    
    sepView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: width, height: 10))
    
    
  // 加入父控件
    addSubview(iconView)
    addSubview(nameLabel)
    addSubview(membershipView)
    addSubview(timeLabel)
    addSubview(destinationLabel)

  // 设立约束
    iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: sepView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: margin, y: margin))
    
    vipView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: -margin*0.5, y: -margin*0.5))
    
    nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: margin, y: 0))
    
    membershipView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: CGPointMake(margin, 0))
    
    timeLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: nameLabel, size: nil, offset: CGPoint(x: 0, y: 5))
    
    destinationLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: timeLabel, size: nil, offset: CGPoint(x: margin, y: 0))
    
    }

   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }

    // 头像
    private lazy var iconView:UIImageView = UIImageView(image: UIImage(named: "avatar"))
    // 姓名
    private lazy var nameLabel:UILabel = UILabel(fontSize: 14, fontColor: UIColor.orangeColor())
    // 会员等级
    private lazy var membershipView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    // 时间
    private lazy var timeLabel:UILabel = UILabel(fontSize: 9, fontColor: UIColor.orangeColor())
    // 来源
    private lazy var destinationLabel:UILabel = UILabel(fontSize: 9, fontColor: UIColor.darkGrayColor())
    // 身份图标
    private lazy var vipView:UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
}
